<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .box {
            width: 600px;
            height: 800px;
            margin: 40px auto;
        }
        .top {
            width: 100%;
            height: 40px;
        }
        .text {
            width: 60px;
            height: 100%;
            float: left;
            background-color: #0f0;
            line-height: 40px;
            text-align: center;
            border: 1px solid #ccc;
            cursor: pointer;
        }
        .middle {
            width: 600px;
            height: 300px;
            position: relative;
        }
        .pic {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        .on {
            display: block;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="top">
            <p class="text">奔驰</p>
            <p class="text">特斯拉</p>
        </div>
        <div class="middle">
            <div class="pic on">
                <img src="images/pic1.png" alt="">
            </div>
            <div class="pic">
                <img src="images/pic2.png" alt="">
            </div>
        </div>
    </div>
    <script>
        var otext = document.querySelectorAll('.top .text'),
            opic = document.querySelectorAll('.middle .pic');
        otext[0].onclick = function(){
            this.style.cssText = ('color:#fff;background-color:#f00');
            otext[1].style.cssText = '';
            opic[0].style.display = 'block';
            opic[1].style.display = 'none';
        }
        otext[1].onclick = function(){
            this.style.cssText = ('color:#fff;background-color:#f00');
            otext[0].style.cssText = '';
            opic[1].style.display = 'block';
            opic[0].style.display = 'none';
        }
    </script>
</body>
</html>